#include "MyStructx.h"

static void hello() {
    printf("hello,struct!\r\n");
}

struct_type_x_1 x1 = {
    .type.type = 1,
    .data = 10
};

struct_type_x_2 x2 = {
    .type.type = 2,
    .func = hello
};


void test2() {
    struct_type_x *x[2]={
        &x1.type,
        &x2.type,
    };

    for(int i=0;i<2;i++) {
        switch (x[i]->type)
        {
            case 1:{
                struct_type_x_1* px1 = (struct_type_x_1*)x[i];
                printf("%d\t%d\r\n",px1->type.type,px1->data);
            } break;
            case 2:{
                struct_type_x_2* px2 = (struct_type_x_2*)x[i];
                //px2->type.type = 5;
                printf("%d\t",px2->type.type);
                px2->func();
            }break;
            
            default:
                break;
        }
    }

}